package com.uniapp.java.uniappjava.service;

import com.uniapp.java.uniappjava.dao.ProductionDao;
import com.uniapp.java.uniappjava.pojo.Production;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lsy_server
 */
@Service
public class ProductionService {
    @Autowired
    private ProductionDao productionDao;

    public List<Production> queryProductions(String authorId, Integer page, Integer limit, String order, String sort) {
        Sort so = new Sort(Sort.Direction.fromString(sort), order);
        Pageable pageable = PageRequest.of(page - 1, limit, so);
        return productionDao.findByAuthorIdExists(authorId, pageable);
    }

    public Production save(Production production) {
        return productionDao.save(production);
    }
}
